package com.kavadani.dialogs;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.KeyEvent;

import com.kavadani.profiles.R;

public class ErrorDlg {
	
	public static final void show(Context context, String title, String message) {
		AlertDialog dlg = showNeutralDialog(context, title, message,
				android.R.drawable.ic_dialog_alert, context.getString(R.string.alert_dialog_ok),
				null);
		dlg.show();
	}
	
	public static final void show(Context context, String title, 
			String message, DialogInterface.OnClickListener onClickListener) {
		AlertDialog dlg = showNeutralDialog(context, title, message,
				android.R.drawable.ic_dialog_alert, context.getString(R.string.alert_dialog_ok),
				onClickListener);
		dlg.show();
	}
	
	
	// --- ---------------------------------------------------------------------------------------
	
	private static AlertDialog showNeutralDialog(Context context, String title, String message,
			int icon_id, String neutralOptionText,
			DialogInterface.OnClickListener neutralListener) {
		AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
		dialogBuilder.setTitle(title).setMessage(message).setIcon(
				icon_id).setNeutralButton(neutralOptionText,
				neutralListener);
		dialogBuilder.setOnKeyListener(new DialogInterface.OnKeyListener() {
			public boolean onKey(DialogInterface dialog, int keyCode,
					KeyEvent event) {
				switch (keyCode) {
				case KeyEvent.KEYCODE_BACK:
					dialog.cancel();
					return true;
				}
				return true;
			}
		});
		return dialogBuilder.create();
	}
}
